﻿using System;
using System.Collections.Generic;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;

namespace IQIGame.Onigao.Logic
{
    public class SkillEffective_Package : SkillEffective
    {
        protected override ISerializeCustomPOD OnExecute(SkillEffectiveData data, Unit target, SkillEffectiveContext context, int effectiveIndex, out SkillEffectiveResponse startResp)
        {
            startResp = null;
            if (data.effectiveConfig.customConfig is SkillEffective_Package_ConfigData rConfig)
            {
                return PackageOnExecute(rConfig.actions, target, ref context, effectiveIndex);
            }
            return null;
        }

        public static ISerializeCustomPOD PackageOnExecute(List<SkillActionNode> actions, Unit rTarget, ref SkillEffectiveContext rContext, int effectiveIndex)
        {
            var rResp = ClassPool.Get<SkillEffectivePackageResponse>();
            for (int i = 0; i < actions.Count; i++)
            {
                var rAction = actions[i];
                var rType = (ESkillEffectiveType)rAction.actionType;
                var rSkillEffective = SkillFactory.GetEffective(rType);
                var rActionResp = rSkillEffective.ActionExecute(null, rAction, rTarget, ref rContext, effectiveIndex);
                rResp.Add(rTarget.GUID, rActionResp);
            }
            return rResp;
        }

#if UNITY_EDITOR
        public override string ToString(SkillCustomConfig config)
        {
            return $"组合效果：";
        }
#endif
    }
}